package com.ruoyi.crm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.crm.domain.CrmOrderProductDiscount;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.domain.CrmOrderRegister;
import com.ruoyi.crm.service.ICrmOrderRegisterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商机项目立项Controller
 *
 * @author yanwenliang
 * @date 2024-11-06
 */
@RestController
@RequestMapping("/crm/orderRegister")
public class CrmOrderRegisterController extends BaseController
{
    @Autowired
    private ICrmOrderRegisterService crmOrderRegisterService;

    /**
     * 查询商机项目立项列表
     */
//    @PreAuthorize("@ss.hasPermi('crm:orderRegister:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmOrderRegister crmOrderRegister)
    {
        startPage();
        List<CrmOrderRegister> list = crmOrderRegisterService.selectCrmOrderRegisterList(crmOrderRegister);
        return getDataTable(list);
    }

    /**
     * 导出商机项目立项列表
     */
//    @PreAuthorize("@ss.hasPermi('crm:orderRegister:export')")
    @Log(title = "商机项目立项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmOrderRegister crmOrderRegister)
    {
        List<CrmOrderRegister> list = crmOrderRegisterService.selectCrmOrderRegisterList(crmOrderRegister);
        ExcelUtil<CrmOrderRegister> util = new ExcelUtil<CrmOrderRegister>(CrmOrderRegister.class);
        util.exportExcel(response, list, "商机项目立项数据");
    }

    /**
     * 获取商机项目立项详细信息
     */
//    @PreAuthorize("@ss.hasPermi('crm:orderRegister:query')")
    @GetMapping(value = "/{orderRegisterId}")
    public AjaxResult getInfo(@PathVariable("orderRegisterId") String orderRegisterId)
    {
        return success(crmOrderRegisterService.selectCrmOrderRegisterByOrderRegisterId(orderRegisterId));
    }

    /**
     * 新增商机项目立项
     */
//    @PreAuthorize("@ss.hasPermi('crm:orderRegister:add')")
    @Log(title = "商机项目立项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmOrderRegister crmOrderRegister)
    {
        return toAjax(crmOrderRegisterService.insertCrmOrderRegister(crmOrderRegister));
    }

    /**
     * 修改商机项目立项
     */
//    @PreAuthorize("@ss.hasPermi('crm:orderRegister:edit')")
    @Log(title = "商机项目立项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmOrderRegister crmOrderRegister)
    {
        return toAjax(crmOrderRegisterService.updateCrmOrderRegister(crmOrderRegister));
    }

    /**
     * 删除商机项目立项
     */
//    @PreAuthorize("@ss.hasPermi('crm:orderRegister:remove')")
    @Log(title = "商机项目立项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderRegisterIds}")
    public AjaxResult remove(@PathVariable String[] orderRegisterIds)
    {
        return toAjax(crmOrderRegisterService.deleteCrmOrderRegisterByOrderRegisterIds(orderRegisterIds));
    }


    /**
     * 审核
     *
     * @param crmOrderRegister
     * @return
     */
    @PostMapping("audit")
    public AjaxResult audit(@RequestBody CrmOrderRegister crmOrderRegister) {
        return AjaxResult.success(crmOrderRegisterService.audit(crmOrderRegister));
    }

    /**
     * 获取项目立项数据
     * @param crmOrderRegister
     * @return
     */
    @PostMapping("/getOrderRegisterInfo")
    public AjaxResult getOrderRegisterInfo(@RequestBody CrmOrderRegister crmOrderRegister){
        CrmOrderRegister register = crmOrderRegisterService.getOrderRegisterInfo(crmOrderRegister);
        return AjaxResult.success(register);
    }
}
